<?php
namespace app\dboard\controller;
use think\captcha;
use think\facade\Cookie;
use think\facade\Session;
use think\facade\Url;
use think\Db;
class Activity extends Base
{
    public function initialize() {
        parent::initialize();
        $returnUrl=Url::build('dboard/mlogin/sign');
        if(!isset($this->AdminAccount['AdminID']) || intval($this->AdminAccount['AdminID'])<=0 || !isset($this->AdminAccount['sid'])){
            if($this->request->isAjax()){
                return $this->print_result(['Code'=>9999,'Msg'=>'请登录']);
            }
            return $this->redirect($returnUrl);
        }
    }
    public function add_activity(){
        return view('activity/add_activity');
    }
    public function infoData(){
        if (!$this->request->isAjax()) {
            $this->res_data['Msg'] = '请求方式错误';
            return $this->print_result($this->res_data);
        }
        $input = $this->request->param(false);
        $sid = isset($input['sid'])?$input['sid']:0;
        if(!$sid){
            $this->res_data['Msg'] = '参数有误';
            return $this->print_result($this->res_data);
        }
        $where = [];
        $where[] = ['sid','=',$sid];
        $info = Db::name('activity')
                ->where($where)
                ->find();
        if($info['pic'])
          $info['cover'] = get_newpic_url($info['pic']);

        $this->res_data['Msg']='OK';
        $this->res_data['Code']=0;
        $this->res_data['Data']=['activity'=>$info];
        return $this->print_result($this->res_data);
   }
   public function doCreateActivity(){
        if (!$this->request->isAjax()) {
            $this->res_data['Msg'] = '请求方式错误';
            return $this->print_result($result);
        }
        $param    = $this->request->param(false);
        $act = Controller('Activity', 'logic');
        $result            = $act->create($param);
        return $this->print_result($result);
   }
   public function editActivityinfo(){
        if (!$this->request->isAjax()) {
            $this->res_data['Msg'] = '请求方式错误';
            return $this->print_result($result);
        }
        $param    = $this->request->param(false);
        $act = Controller('Activity', 'logic');
        $result            = $act->edit($param);
        return $this->print_result($result);
   }
}
